/**
 * Licensed to Open-Ones Group under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Open-Ones Group licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a
 * copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package vn.fpt.fsoft.menugame;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
import java.text.AttributedString;

/**
 * @author Len Nguyen
 *
 */
public class RadioItem {
    
    private BufferedImage image1;
    private BufferedImage image2;
    private int x;
    private int y;
    private String name;
    private boolean isSelect;
    private Color color;
    AttributedString attString;
    
    public BufferedImage getImage1() {
        return image1;
    }
    public void setImage1(BufferedImage image1) {
        this.image1 = image1;
    }
    public BufferedImage getImage2() {
        return image2;
    }
    public void setImage2(BufferedImage image2) {
        this.image2 = image2;
    }
    public int getX() {
        return x;
    }
    public void setX(int x) {
        this.x = x;
    }
    public int getY() {
        return y;
    }
    public void setY(int y) {
        this.y = y;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public boolean isSelect() {
        return isSelect;
    }
    public void setSelect(boolean isSelect) {
        this.isSelect = isSelect;
    }
    public Color getColor() {
        return color;
    }
    public void setColor(Color color) {
        this.color = color;
    }
    public AttributedString getAttString() {
        return attString;
    }
    public void setAttString(AttributedString attString) {
        this.attString = attString;
    }
    
    public RadioItem(BufferedImage image1, BufferedImage image2, int x, int y, String name, Color color) {
        super();
        this.image1 = image1;
        this.image2 = image2;
        this.x = x;
        this.y = y;
        this.name = name;
        this.color = color;
    }
    public void draw(Graphics2D g2d) {
        
        if(isSelect){
            color = Color.BLUE;
            g2d.drawImage(image1, x, y, null);
            Font font = new Font("Cambria", Font.ITALIC, 25);
            g2d.setFont(font);
            FontMetrics fontMetrics = g2d.getFontMetrics();
            int height = fontMetrics.getHeight();
            int width = fontMetrics.stringWidth(name);
            Point posText = new Point(x + (image1.getWidth() - width) / 2, y + (image1.getHeight() - height) / 2 + 15);
            attString = new AttributedString(name);
            attString.addAttribute(TextAttribute.FOREGROUND, color, 0,
                    name.length());
            attString.addAttribute(TextAttribute.FONT, font);
            
            g2d.drawString(attString.getIterator(), posText.x + 75, posText.y + 5);
        }
        else{
            color = Color.BLACK;
            g2d.drawImage(image2, x, y, null);
            Font font = new Font("Cambria", Font.ITALIC, 25);
            g2d.setFont(font);
            FontMetrics fontMetrics = g2d.getFontMetrics();
            int height = fontMetrics.getHeight();
            int width = fontMetrics.stringWidth(name);
            Point posText = new Point(x + (image1.getWidth() - width) / 2, y + (image1.getHeight() - height) / 2 + 15);
            attString = new AttributedString(name);
            attString.addAttribute(TextAttribute.FOREGROUND, color, 0,
                    name.length());
            attString.addAttribute(TextAttribute.FONT, font);
            
            g2d.drawString(attString.getIterator(), posText.x + 75, posText.y + 5);
        }
    }
}
